package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.*;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class CDao {

	DBHelp<Contact> db=new DBHelp<Contact>();
	
	public void save(Contact c){
		String sql="insert into t_contact(id,cname,company,telephone,email,address,website,weibo,descripe,projectid,createtime) values(?,?,?,?,?,?,?,?,?,?,?)";
		db.executeSQL(sql,c.getId(),c.getCname(),c.getCompany(),c.getTelephone(),c.getEmail(),c.getAddress(),c.getWebsite(),c.getWeibo(),c.getDescripe(),c.getProjectid(),c.getCreatetime());
	}
	
	public List<Contact> findByProjecid(String pid){
		String sql="select * from t_contact where projectid=?";
		return db.queryForList(sql,new CRowMapper(),pid);
	}
	
	private class CRowMapper implements RowMapper<Contact>{

		public Contact mapperRow(ResultSet rs) throws SQLException {
			
			Contact c=new Contact();
			c.setAddress(rs.getString("address"));
			c.setCname(rs.getString("cname"));
			c.setCompany(rs.getString("company"));
			c.setCreatetime(rs.getString("createtime"));
			c.setDescripe(rs.getString("descripe"));
			c.setEmail(rs.getString("email"));
			c.setId(rs.getString("id"));
			c.setProjectid(rs.getString("projectid"));
			c.setTelephone(rs.getString("telephone"));
			c.setWebsite(rs.getString("website"));
			c.setWeibo(rs.getString("weibo"));
			
			return c;
		}
		
	}
}
